package com.example.springboot.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.example.springboot.common.Result;
import com.example.springboot.controller.request.ActivityPageRequest;
import com.example.springboot.entity.Admin;
import com.example.springboot.entity.Activity;
import com.example.springboot.service.impl.ActivityService;
import com.example.springboot.utils.TokenUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activity")
public class ActivityController {


    @Autowired
    ActivityService activityService;

    //保存
    @PostMapping("/save")
    public Result login(@RequestBody Activity activity) {
        activityService.save(activity);
        return Result.success();
    }

    //更新
    @PutMapping("/update")
    public Result update(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }


    //获取
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Activity admins = activityService.getById(id);
        return Result.success(admins);
    }

    //单个删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        activityService.deleteById(id);
        return Result.success();
    }


    //   查询全部
    @GetMapping("/list")
    public Result list() {
        List<Activity> users = activityService.list();
        return Result.success(users);
    }


    //    分页查询
    @GetMapping("/page")
    public Result page(ActivityPageRequest activityPageRequest) {
        return Result.success(activityService.page(activityPageRequest));
    }


}
